<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./OL_SDK/include-openlayers-local.js"></script>
    <script src="./libs/gaode.js"></script>
    <script src="https://lib.baomitu.com/jquery/2.2.4/jquery.js"></script>
</head>

<body>
    <div id="map">
    </div>
    <script>
        var map = new ol.Map({
            target: "map",
            layers: [gaode],
            view: new ol.View({
                projection: 'EPSG:4326',
                center: [114.30, 30.50],
                zoom: 4
            })
        })
        /* axios-jsonp */
        var url = 'https://apis.map.qq.com/ws/location/v1/ip?key=5SHBZ-N3D3I-M4IGS-5Y7DV-RQXEQ-SRBNV&output=jsonp'
        $.ajax({
            url,
            dataType: "jsonp"
        }).then(data => {
            console.log(data,'data')
            const res = data.result
            var { location, ad_info } = res;
            console.log(location)// {lng,lat}
            let adcode = ad_info.adcode;
            console.log(adcode)// 211281
            var geojson_url = `https://geo.datav.aliyun.com/areas_v3/bound/${adcode}.json`;
            var source = new ol.source.Vector({
                format: new ol.format.GeoJSON(),
                url: geojson_url
            })
            var layer = new ol.layer.Vector({
                source
            })
            map.addLayer(layer)

            const style = new ol.style.Style({
                /**{olx.style.IconOptions}类型*/
                image: new ol.style.Icon({
                    anchor: [0.5, 60],
                    anchorOrigin: 'top-right',
                    anchorXUnits: 'fraction',
                    anchorYUnits: 'pixels',
                    offsetOrigin: 'top-right',
                    // offset:[0,10],
                    //图标缩放比例
                    scale: 0.5,
                    //透明度
                    opacity: 0.75,
                    //图标的url
                    src: '/images/location.png',
                }),
            })
            const point = new ol.Feature({
                geometry: new ol.geom.Point([location.lng, location.lat]),
            })
            point.setStyle(style)

            let point_source = new ol.source.Vector({
                features:[point]
            })
            let point_layer = new ol.layer.Vector({
                source:point_source
            })
            map.addLayer(point_layer)
        })
    </script>
</body>

</html>